import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created by fjc on 2017/3/14.
 */
public class HyperLogLog {
    //直接创建jedis
//    Jedis jedis = new Jedis("localhost",6379);
    //创建对象池
    JedisPool jedisPool = new JedisPool(new JedisPoolConfig(),"localhost",6379);
    //获取jedis
    Jedis jedis = jedisPool.getResource();

    @Test
    public void pfAdd(){
        //添加指定元素到 HyperLogLog 中
        jedis.pfadd("p1","1","2","3","4");
    }

    @Test
    public void pfCount(){
        //返回给定 HyperLogLog 的基数估算值
        System.out.println(jedis.pfcount("p1"));
    }

    @Test
    public void pgMerge(){
        //将多个 HyperLogLog 合并为一个 HyperLogLog
        jedis.pfadd("p1","1","2","3","4");
        jedis.pfadd("p2","5","6","7","8");
        jedis.pfmerge("p3","p2","p1");
    }
}
